package com.toune.villager.wxapi

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.tamsiree.rxkit.view.RxToast
import com.tencent.mm.opensdk.constants.ConstantsAPI
import com.tencent.mm.opensdk.modelbase.BaseReq
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
import com.toune.wxtool.WxTool

class WXEntryActivity:Activity(), IWXAPIEventHandler {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        WxTool.api!!.handleIntent(intent,this)
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        setIntent(intent)
        WxTool.api!!.handleIntent(intent,this)
    }

    override fun onReq(req: BaseReq?) {

    }

    override fun onResp(resp: BaseResp?) {
        when(resp!!.type){
            ConstantsAPI.COMMAND_SENDAUTH->{
                //登录
                val code = (resp as SendAuth.Resp).code
                val country = (resp as SendAuth.Resp).country
                RxToast.showToast("国家$country.code：$code")
            }
            ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX->{

            }
        }
    }

}